package org.example.review.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.review.dto.DepartmentDTO;

import java.util.List;

@Mapper
public interface DepartmentMapper extends BaseMapper<com.common.pojo.entity.Department> {

    @Select("SELECT d1.*, d2.dept_name as parent_name " +
            "FROM t_department d1 " +
            "LEFT JOIN t_department d2 ON d1.parent_id = d2.id " +
            "WHERE d1.status = 1 " +
            "ORDER BY d1.create_time ASC")
    List<DepartmentDTO> selectDepartmentList();

    @Select("SELECT d1.*, d2.dept_name as parent_name " +
            "FROM t_department d1 " +
            "LEFT JOIN t_department d2 ON d1.parent_id = d2.id " +
            "WHERE d1.id = #{id} AND d1.status = 1")
    DepartmentDTO selectDepartmentById(Integer id);

    @Select("SELECT * FROM t_department WHERE parent_id = #{parentId} AND status = 1")
    List<DepartmentDTO> selectDepartmentsByParentId(Integer parentId);
}
